package com.hou.controller;

import com.hou.EX.ServicesException.IdnotException;
import com.hou.EX.ServicesException.ServiceException;
import com.hou.EX.ServicesException.VipLoginNotPhoneException;
import com.hou.EX.ServicesException.VipPasswordErrorException;
import com.hou.EX.uploadException.*;
import com.hou.vo.JsonResult;
import org.springframework.web.bind.annotation.ExceptionHandler;

public class BaseController {

    public static final int OK = 200;

    @ExceptionHandler({ServiceException.class, FileUploadException.class})
    public JsonResult<Void> handleException(Throwable e) {
        JsonResult<Void> result = new JsonResult<Void>(e);
        if (e instanceof FileEmptyException) {
            result.setState(6000);
        } else if (e instanceof FileSizeException) {
            result.setState(6001);
        } else if (e instanceof FileTypeException) {
            result.setState(6002);
        } else if (e instanceof FileStateException) {
            result.setState(6003);
        } else if (e instanceof FileUploadIOException) {
            result.setState(6004);
        } else if (e instanceof IdnotException) {
            result.setState(5000);
        } else if (e instanceof VipLoginNotPhoneException){
            result.setState(4000);
        } else if (e instanceof VipPasswordErrorException){
            result.setState(4001);
        }
        return result;
    }
}
